package _mst;

import java.util.ArrayList;
import java.util.List;

/**
 * 面试题 08.07. 无重复字符串的排列组合
 */
public class T0807 {
    private List<String> ans;
    private StringBuilder path;
    private String S;

    public String[] permutation(String S) {
        ans = new ArrayList<>();
        path = new StringBuilder();
        this.S = S;
        dfs(0);
        return ans.toArray(new String[0]);
    }

    private void dfs(int i) {
        if (i == S.length()) {
            ans.add(path.toString());
            return;
        }
        for (char c : S.toCharArray()) {
            if (path.indexOf(String.valueOf(c)) != -1) continue;
            path.append(c);
            dfs(i + 1);
            path.deleteCharAt(i);
        }
    }
}
